package com.recruit.g1.company.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.recruit.g1.common.response.JsonResult;
import com.recruit.g1.company.mapper.CompanyMapper;
import com.recruit.g1.pojo.company.dto.CompanyAddParam;
import com.recruit.g1.pojo.company.entity.Company;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpSession;

@Validated
@Slf4j//nei
@Api(tags = "企业详情管理模块")
@RestController
@RequestMapping("/company")
public class CompanyController {

    @Autowired
    private CompanyMapper companyMapper;

    /**
     * 1.添加企业详情
     */
    @PostMapping("add")
    @ApiOperation("添加企业信息")
    @ApiOperationSupport(order = 10)
    public JsonResult insertCompany(@RequestBody CompanyAddParam companyAddParam, @ApiIgnore HttpSession session) {
        log.debug("companyAddParam ="+ companyAddParam);
        //获取用户信息(登陆状态拦截)
        //User userSaveParam =(User) session.getAttribute("currentLoginUser");//////////////////////////////////////////////////////
        /*if (userSaveParam == null) {
            log.error("User not logged in or session expired.");
            return JsonResult.error("User not logged in or session expired.");
        }*/
        //登陆状态
        Company company = new Company();
        BeanUtils.copyProperties(companyAddParam, company);
        log.debug("company ="+ company);
        companyMapper.insert(company);

        return JsonResult.ok();
    }
}
